﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="../demo.css" rel="stylesheet" type="text/css" />

    <script src="../../../SFramework/boot.js"></script>

    <style type="text/css">
        html, body {
            padding: 0;
            margin: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div class="mini-toolbar" style="text-align:center;line-height:30px;"
         borderstyle="border-left:0;border-top:0;border-right:0;">
        <label>名称：</label>
        <input id="key" class="mini-textbox" style="width:150px;" onenter="onKeyEnter" />
        <a class="mini-button" style="width:60px;" onclick="search()">查询</a>
    </div>
    <div class="mini-fit">

        <ul id="tree1" class="mini-tree" style="width:100%;height:100%;"
            showtreeicon="true" textfield="name" idfield="id" parentfield="parent_id" resultastree="false"
            expandonload="true" onnodedblclick="onNodeDblClick" expandondblclick="false" showcheckbox="true" checkrecursive="false"
            expandonload="true" allowselect="true" enablehottrack="false"></ul>

    </div>
    <div class="mini-toolbar" style="text-align:center;padding-top:8px;padding-bottom:8px;"
         borderstyle="border-left:0;border-bottom:0;border-right:0;">
        <a class="mini-button" style="width:60px;" onclick="onOk()">确定</a>
        <span style="display:inline-block;width:25px;"></span>
        <a class="mini-button" style="width:60px;" onclick="onCancel()">取消</a>
    </div>

</body>
</html>
<script src="../../../Scripts/common/jquery.data.js"></script>
<script type="text/javascript">
    mini.parse();

    var tree = mini.get("tree1");
    tree.load("/extendpage/data/jsondata.aspx?entity=t_sys_function&type=1");

    function SetData() {
        var data = fnGetData("t_sys_role_function", "role_id='" + getPar("roleid") + "'").data;
        var node = tree.getRootNode();
        tree.checkNode(node);

        var nodes = tree.getAllChildNodes(node)
        $.each(nodes, function (i) {
            $.each(data, function (e) {
                //debugger
                if (data[e].function_id == nodes[i].id) {

                    tree.checkNode(nodes[i]);
                }
            });
        });
    }



    function GetData() {
        var nodes = tree.getCheckedNodes();
        return nodes;
    }
    function search() {
        var key = mini.get("key").getValue();
        if (key == "") {
            tree.clearFilter();
        } else {
            key = key.toLowerCase();
            tree.filter(function (node) {
                var text = node.text ? node.text.toLowerCase() : "";
                if (text.indexOf(key) != -1) {
                    return true;
                }
            });
        }
    }
    function onKeyEnter(e) {
        search();
    }
    function onNodeDblClick(e) {
        onOk();
    }
    //////////////////////////////////
    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }

    function onOk() {
        //var node = tree.getSelectedNode();
        //if (node && tree.isLeaf(node) == false) {
        //    alert("不能选中父节点");
        //    return;
        //}

        CloseWindow("ok");
    }
    function onCancel() {
        CloseWindow("cancel");
    }

    //获取URL querystring parameter
    function getPar1(source, name) {
        var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
        if (reg.test(source)) return RegExp.$2; return "";
    }

    function getPar(name) {
        var _url = "http://" + document.location;
        return getPar1(_url, name);
    }
    SetData();
</script>
